<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

        let cites = [{
            py: 'beijing',
            name: '北京'
        },
        {
            py: 'alishan',
            name: '阿里山'
        },
        {
            py: 'beidaihe',
            name: '北戴河'
        },
        {
            py: 'shijiazhuang',
            name: '石家庄'
        }
        ]

        let arr = {}  

        for (let i = 0; i < str.length; i++) {
            arr[str[i]] = []  
            cites.forEach(function (item,index) {  //循环对象
                if (item.py.toUpperCase().substr(0, 1) == str[i]) {
                    arr[str[i]].push(item)
                }
            })
        }
        console.log(arr);
    </script>
</body>

</html>